package client;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JFrame;

public class Client {

	public static final boolean DEBUG = true;

	public Client(String ip) throws UnknownHostException, IOException {

		InetAddress ipAddr = InetAddress.getByName(ip);

		ClientController controller = new ClientController(
				new File("").getAbsolutePath());
		controller.connect(ipAddr, 8080);

		initInterface(controller);
	}

	/*
	 * Show the gui. test
	 */
	private void initInterface(Container panel) {
		JFrame frame = new JFrame("Peer-to-peer FTP");
		frame.setMinimumSize(new Dimension(600, 300));
		frame.setContentPane(panel);
		frame.pack();
		frame.setLocationRelativeTo(frame.getRootPane());
		frame.setVisible(true);

		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

}
